// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using Microsoft.Extensions.DependencyInjection;
using static Common.Grammar.Antlr.CommonParser;

namespace SnapObjects.Expressions
{
    public static partial class ExpressionsServiceCollectionExtensions
    {
        public static IServiceCollection AddEvaluateExpression(this IServiceCollection services)
        {
            services
                .AddExpressionCore<EvaluateResult>()
                .AddEvaluateVisitors()
                .AddEvaluateMetadataProviders();

            services.AddTransient<EvaluateMethodMatcher>();

            services.AddTransient<IEvaluateExpressionParser, EvaluateExpressionParser>();

            services.AddTransient<IPolicyProvider<EvaluateResult>, EvaluatePolicyProvider>();

            services.AddTransient<IMetadataManager<EvaluateResult>, EvaluateMetadataManager>();

            services.AddTransient<INestParseProvider<EvaluateResult>, EvaluateNestParseProvider>();

            return services;
        }

        private static IServiceCollection AddEvaluateVisitors(this IServiceCollection services)
        {
            services.AddVisitors<EvaluateResult>();

            services.AddTransient<INodeExpressionVisitor<EvaluateResult>, EvaluateNewExpressionVisitor<Expression_newContext>>();

            return services;
        }

        private static IServiceCollection AddEvaluateMetadataProviders(this IServiceCollection services)
        {
            services.AddTransient<IMetadataProvider<EvaluateResult>, DefaultEvaluateMethodProvider>();

            services.AddTransient<IMetadataProvider<EvaluateResult>, DefaultEvaluatePropertyProvider>();

            return services;
        }
    }
}
